package edu.utexas.ipc;

public class DirectClock implements Clock {

    private int[] clock;
    private int myId;
    
    public DirectClock(int numProc, int id) {
        myId = id;
        clock = new int[numProc];
        for (int i = 0; i < numProc; i++) clock[i] = 0;
        clock[myId] = 1;
    }
    
    public int getValue(int i) {
        return clock[i];
    }
    
    public void tick() {
        clock[myId]++;
    }
    
    public void receiveAction(int sender, int sentValue) {
        clock[sender] = Math.max(clock[sender], sentValue);
        clock[myId] = Math.max(clock[myId], sentValue) + 1;
    }

	public void update(int srcID, String timestamp) {
		receiveAction(srcID, Integer.parseInt(timestamp));
	}

	public String value() {
		return Integer.toString(getValue(myId));
	}

}
